#include "gdt.h"

gdt_entry gdt[GDT_COUNT] = {
	//0x00 Descriptor nulo
	(gdt_entry){ 
		(unsigned short) 0x0000,	//limit_0_15
		(unsigned short) 0x0000,	//base_0_15
		(unsigned char) 0x00,		//base_23_16
		(unsigned char) 0x0,			//type
		(unsigned char) 0,			//s
		(unsigned char) 0,			//dpl
		(unsigned char) 0,			//p
		(unsigned char) 0x0000,		//limit_16_19
		(unsigned char) 0,			//avl
		(unsigned char) 0,			//l
		(unsigned char) 0,			//db
		(unsigned char) 0,			//g
		(unsigned char) 0x00			//base_31_24
	},
	
	//0x08 Codigo Kernel
	(gdt_entry){ 
		(unsigned short) 0xFFFF, 
		(unsigned short) 0x0000,
		(unsigned char) 0x00, 
		(unsigned char) 9, 		// 1001b = Codigo - ¬ ExpandDown - readEnable - Accessed
		(unsigned char) 1, 		// Es de datos o codigo
		(unsigned char) 0, 		// Ring 0
		(unsigned char) 1, 		// Segment present
		(unsigned char) 0xF,
		(unsigned char) 0,  	// Siempre en 0 (reservado)
		(unsigned char) 0,   	// Siempre en 0 (reservado)
		(unsigned char) 1,  	// Byte = 32 bit mode (en 0 es 16bit mode)
		(unsigned char) 0, 		// granularity: byte
		(unsigned char) 0x00 
	},
	
	//0x10 Datos Kernel
	(gdt_entry){ 
		(unsigned short) 0xFFFF, 
		(unsigned short) 0x000,
		(unsigned char) 0x00, 
		(unsigned char) 3,
		(unsigned char) 1, 		// Es de datos o codigo
		(unsigned char) 0, 		// Ring 0
		(unsigned char) 1, 		// Segment present
		(unsigned char) 0xF,
		(unsigned char) 0,  	// Siempre en 0 (reservado)
		(unsigned char) 0,   	// Siempre en 0 (reservado)
		(unsigned char) 1,  	// Byte = 32 bit
		(unsigned char) 0, 		// granularity: byte
		(unsigned char) 0x00 
	},

	//0x18 Memoria de video
	(gdt_entry){ 
		(unsigned short) 0xFFFF, 
		(unsigned short) 0x8000,
		(unsigned char) 0x0B, 
		(unsigned char) 0x2,	 	// 0011b = Datos - NonConforming - ¬ writeEnable - Accessed
		(unsigned char) 1, 		// Es de datos o codigo
		(unsigned char) 0, 		// Ring 0
		(unsigned char) 1, 		// Segment present
		(unsigned char) 0xF,
		(unsigned char) 0,  	// Siempre en 0 (reservado)
		(unsigned char) 0,   	// Siempre en 0 (reservado)
		(unsigned char) 1,  	// Byte = 32 bit
		(unsigned char) 0, 		// granularity: byte
		(unsigned char) 0x00 
	}
};

gdt_descriptor GDT_DESC = {sizeof(gdt)-1, (unsigned int)&gdt};
